package info.androidhive.slidingmenu.adapter;

import info.androidhive.slidingmenu.R;
import info.androidhive.slidingmenu.Songs;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SongsAdapter extends BaseAdapter {

	private ArrayList<Songs> songs;
	private LayoutInflater songInf;

	public SongsAdapter(Context c, ArrayList<Songs> theSongs) {
		songs = theSongs;
		songInf = LayoutInflater.from(c);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return songs.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		// map to song layout
		LinearLayout songLay = (LinearLayout) songInf.inflate(R.layout.activity_song,
				parent, false);
		// get title and artist views
		TextView songView = (TextView) songLay.findViewById(R.id.txtSongTitle);
		TextView artistView = (TextView) songLay.findViewById(R.id.txtSongArtist);
		// get song using position
		Songs currSong = songs.get(position);
		// get title and artist strings
		songView.setText(currSong.getTitle());
		artistView.setText(currSong.getArtist());
		// set position as tag
		songLay.setTag(position);
		return songLay;
	}
}
